"""
Case Type   : SQL_LIMIT
Case Name   : 查看系统表结果是否正确
Create At   : 2025/9/16
Owner       : lonely-dance
Description :
    1、查看系统表 gs_sql_limit结构
Expect      :
    1、表字段包括（limit_id, limit_name, work_node, max_concurrency, start_time, end_time, limit_type, databases, users,
       limit_opt），索引为btree索引，tablespace为pg_global
History     :
"""

import os
import unittest
from testcase.utils.Logger import Logger
from testcase.utils.CommonSH import CommonSH


class SqlLimit(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'----- {os.path.basename(__file__)} start-----')
        self.comm_sh = CommonSH('PrimaryDbUser')
        self.list = ['limit_id', 'limit_name', 'is_valid', 'work_node', 'max_concurrency', 'start_time', 'end_time',
                     'limit_type', 'databases', 'users', 'limit_opt',
                     '\"gs_sql_limit_id_index\" btree (limit_id) TABLESPACE pg_global', 'Tablespace: \"pg_global\"']

    def test_main(self):
        text = '----step1:查看系统表 gs_sql_limit结构 expect:成功----'
        self.log.info(text)
        cmd = '\\d+ gs_sql_limit;'
        res = self.comm_sh.execut_db_sql(cmd)
        self.log.info(res)
        for element in self.list:
            self.assertIn(element, res, 'gs_sql_limit结构异常')

    def tearDown(self):
        text = '----无需恢复环境----'
        self.log.info(text)
        self.log.info(f'----- {os.path.basename(__file__)} end-----')


